/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cs425proj.model;

import java.sql.*;

/**
 *
 * @author prateekpatil
 */
public class MemberDetail {
    
   
    
    private int member_id;
    private String f_name;
    private String l_name;
    private String username;
    private String password;
    private String member_type;
    private String email;
    private int phone;
    private int total_points;
    private int points_spent;
    private String address;
    private String city;
    private String state;
    private int zipcode;

    public void selectMemberData(String username){
    
         ResultSet rs;
        try{
        connectDB obj = new connectDB();
        
        Statement stm;
        stm =  obj.startConnection().createStatement();
        //Querries
        rs = stm.executeQuery("select * from member where username='"+username+"'");
        
        while(rs.next()){
                this.setMember_id(rs.getInt(1));
                this.setF_name(rs.getString(2));
                this.setL_name(rs.getString(3));
                this.setUsername(rs.getString(4));
                this.setPassword(rs.getString(5));
                this.setMember_type(rs.getString(6));
                this.setEmail(rs.getString(7));
                this.setPhone(rs.getInt(8));
                this.setTotal_points(rs.getInt(9));
                this.setPoints_spent(rs.getInt(10));
                this.setAddress(rs.getString(11));
                this.setCity(rs.getString(12));
                this.setState(rs.getString(13));
                this.setZipcode(rs.getInt(14));
        }
       
        
        
        obj.closeConnection();
        }catch(SQLException e){e.printStackTrace();}
    }
    
    public void insertMemberData(){
    
        
         ResultSet rs;
        try{
        connectDB obj = new connectDB();
        
       
            Connection con =  obj.startConnection();
         
            String qry = "update member set email='"+this.getEmail()+"',phone='"+this.getPhone()+"',address ='"+this.getAddress()+"',city='"+this.getCity()+"',state='"+this.getState()+"',zipcode='"+this.zipcode
                    +"' where username = '"+this.getUsername()+"'";
            PreparedStatement pstmt = con.prepareStatement(qry);
            pstmt.executeUpdate();
            
            obj.closeConnection();
        }catch(SQLException e){e.printStackTrace();}
    
    }
    
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getF_name() {
        return f_name;
    }

    public void setF_name(String f_name) {
        this.f_name = f_name;
    }

    public String getL_name() {
        return l_name;
    }

    public void setL_name(String l_name) {
        this.l_name = l_name;
    }

    public int getMember_id() {
        return member_id;
    }

    public void setMember_id(int member_id) {
        this.member_id = member_id;
    }

    public String getMember_type() {
        return member_type;
    }

    public void setMember_type(String member_type) {
        this.member_type = member_type;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getPhone() {
        return phone;
    }

    public void setPhone(int phone) {
        this.phone = phone;
    }

    public int getPoints_spent() {
        return points_spent;
    }

    public void setPoints_spent(int points_spent) {
        this.points_spent = points_spent;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public int getTotal_points() {
        return total_points;
    }

    public void setTotal_points(int total_points) {
        this.total_points = total_points;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getZipcode() {
        return zipcode;
    }

    public void setZipcode(int zipcode) {
        this.zipcode = zipcode;
    }
    
    
    
}
